package com.example.healthapp.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

// SP工具类
public class SPManage {

    private static SharedPreferences sharedPreferences;
    private static SharedPreferences.Editor editor;
    static SPManage spManage;

    //单例模式
    public static SPManage getSP(Context context, String name) {
        if (spManage == null) {
            Log.d("phcc", "getSP:创建 ");
            sharedPreferences = context.getSharedPreferences(name, Context.MODE_PRIVATE);
            editor = sharedPreferences.edit();
            spManage = new SPManage();
        }
        return spManage;
    }

    public String getString(String name) {
        return sharedPreferences.getString(name, "");
    }

    public SPManage putString(String name, String value) {
        editor.putString(name, value);
        return spManage;
    }

    public void commit() {
        editor.commit();
    }
}